<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"
    errorPage=""
    import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="mydb" scope="page" class="bean.ConDbBean"/> <%//連結資料庫的bean %>
<jsp:useBean id="md5" scope="page" class="bean.MD5Bean"/>
<% 
session.setAttribute("access","n") ;  
if(request.getParameter("memberid") !=null  &&  
   request.getParameter("memberpwd") != null){

	//將輸入的密碼轉成md5的格式,且比對資料庫的欄位
	String md5_pwd=md5.getMD5(request.getParameter("memberpwd"));
    String sql = "SELECT * FROM MEMBER WHERE M_ID='" + 
            request.getParameter("memberid") + "'  AND PW='" + 
            md5_pwd + "'"  ; 
    ResultSet rs =mydb.executeQuery(sql) ;
    
    if(rs.next()){            
        session.setAttribute("access","y") ; 
        session.setAttribute("accessid",request.getParameter("memberid")) ;
        session.setMaxInactiveInterval(600) ; 
       
          int level=java.lang.Integer.valueOf(rs.getString("LEVEL_ID"));
          if(level==2){  //判斷權限
          session.setAttribute("level","2");
          //response.sendRedirect("managepage.jsp") ;
          }
          else if(level==1){
          session.setAttribute("level","1");
          //response.sendRedirect("memberpage.jsp") ;
          }
          else {
          session.setAttribute("level","3");
          //response.sendRedirect("memberpage.jsp") ;
          }
          //登入前先去檢查今日是否有逾期的借用資料
          response.sendRedirect("../DELAY/do_addDelay.jsp") ;
    }else
        out.println("密碼帳號不符 !!") ;
}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>場地設備管理系統-登入</title>
</head>
<body>

<table width="750" border="0" align="center">
  <tr>
    <td width="30" rowspan="4"><jsp:include page="../frameset/left.jsp" flush="true" ></jsp:include></td>
    <td colspan="2"><jsp:include page="../frameset/top.jsp" flush="true" ></jsp:include></td>
    <td width="40" rowspan="4"><jsp:include page="../frameset/right.jsp" flush="true" ></jsp:include></td>
  </tr>
  <tr>
    <td rowspan="2"></td>
    <td height="32"></td>
  </tr>
  <tr>
    <td>
    <form method="post">
<table border="0" width="500" align="center">
    <tr>
      <td width="500" align="left" colspan="2">
       <b><font size="5">登入場地設備管理系統</font></b>
        <hr>
      </td>
    </tr>
    <tr>
      <td width="75" align="center">
        <p align="right">帳號：</p>
      </td>
      <td width="500" align="center">
        <p align="left"><input type="text" name="memberid" size="20">
        </td>
    </tr>
    <tr>
      <td width="75" align="center">
        <p align="right">密碼：</p>
      </td>
      <td width="500" align="center">
        <p align="left">
        <input type="password" name="memberpwd" size="20">
        <input type="submit" value="登入" name="loginButton"></td>
    </tr>
 
</table>
</form>
    </td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>
</body>
</html>